package com.woniu.elderly.wares.exception;


import com.woniu.common.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

//统一异常处理
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public Result doException(Exception e){
        e.printStackTrace();
        log.info("exception-class:" + e.getClass());
        log.info("exception-class:" + e.getMessage());
        return new Result(500, "商品系统维护中，稍后再试", null);
    }
    @ExceptionHandler
    public Result doRuntimeException(RuntimeException e){
        e.printStackTrace();
        log.info("exception-class:" + e.getClass());
        log.info("exception-class:" + e.getMessage());
        return new Result(502, e.getMessage(), null);
    }

}
